import xlrd

global SheetNumber

class excle_option:
    def __init__(self,filename):
        '''
        :param filename: test case file
        :param sheetNum: excel tab num
        '''
        self.fname = filename
        # self.shtNum = sheetNum
        # self.totalSheet = 0
        # 总用例数统计
        self.total_num = 0
        # 失败总数
        self.fail_count = 0
        # 阻塞总数
        self.block_count = 0
        # 通过总数
        self.pass_count = 0
        # 未测试总数
        self.notTest_count = 0
        # 废弃用例
        self.notAcpt_count = 0

    def getSheetNum(self):
        global SheetNumber
        workbook = xlrd.open_workbook(self.fname)
        all_SheetList = workbook.sheet_names()
        SheetNumber = len(all_SheetList)
        print('所有sheet名字：',all_SheetList)
        print('sheet总数',SheetNumber)
        print(type(SheetNumber))
        return SheetNumber

    def getSheetList(self,sheet_index,collect):
        workbook = xlrd.open_workbook(self.fname)
        sheet = workbook.sheet_by_index(sheet_index)
        sheetName =sheet.name
        sheetRows = sheet.nrows
        sheetCols = sheet.ncols
        print('sheet名字',sheetName)
        print('sheet行数',sheetRows)
        print('sheet列数',sheetCols)

        # 实例化待女子表对象
        Sheet = workbook.sheet_by_name(sheetName)

        for i in range(Sheet.nrows):
            rows = Sheet.row_values(i)
            # print(rows[8])
            if rows[collect] == 'FAIL':
                self.fail_count += 1
                self.total_num += 1
            elif rows[collect] == 'BLOCK':
                self.block_count += 1
                self.total_num += 1
            elif rows[collect] == 'PASS':
                self.pass_count += 1
                self.total_num += 1
            elif rows[collect] == 'NOT TEST':
                self.notTest_count += 1
                self.total_num += 1
            elif rows[collect] == 'NOT ACCESS':
                self.notAcpt_count += 1
                # self.total_num += 1
                # print(rows)
                # fp.write_file(rows)
        print('Total %s Fail %s Block %s Pass %s NOT_TEST %s NOT_ACCESS %s' % (
            self.total_num, self.fail_count, self.block_count, self.pass_count, self.notTest_count, self.notAcpt_count))




if __name__ == '__main__':
    rfile = 'E:/日常资料/工作需求文档/XU/XU1.0系统测试用例-vmware.xls'
    result = excle_option(rfile)
    result.getSheetNum()
    global SheetNumber


    sn = 3
    col = 8
    print(23 * '*' + '第一轮测试' + 23 * '*')
    result.getSheetList(sn, 8)
    print(23 * '*' + '第二轮测试' + 23 * '*')
    result.__init__(rfile)
    result.getSheetList(sn, col + 5)
    print(23 * '*' + '第三轮测试' + 23 * '*')
    result.__init__(rfile)
    result.getSheetList(sn, col + 10)

    # i = 1
    # for i in range(SheetNumber):
    #     if i == 0:
    #         pass
    #     else:
    #         col = 8
    #         print(23*'*'+'第一轮测试'+23*'*')
    #         result.getSheetList(i, 8)
    #         print(23*'*'+'第二轮测试'+23*'*')
    #         result.__init__(rfile)
    #         result.getSheetList(i, col + 5)
    #         print(23*'*'+'第三轮测试'+23*'*')
    #         result.__init__(rfile)
    #         result.getSheetList(i, col + 10)




    # def get_testResutl(self,shtNum):
    #
    #     print(shtNum)
    #     # 电子表索引从0开始
    #     Sheet1 = workbook.sheet_by_index(1)
    #     # 实例化待女子表对象
    #     Sheet1 = workbook.sheet_by_name(SheetName)

